package catcatcat;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
public class ShiLiMysql {
	String JDBC_DRIVER="com.mysql.jdbc.Driver";
	String DB_URL="jdbc:mysql://localhost:3306/miaoshe";
	String USER="root";
	String PASS="123456";
	public ShiLiMysql(){
		Connection conn=null;
		Statement stmt=null;
		
		try {
			Class.forName("com.mysql.jdbc.Driver");
			System.out.println("连接数据库。。。");
			conn=(Connection) DriverManager.getConnection(DB_URL,USER,PASS);
			System.out.println("实例化Statement对象。");
			stmt=(Statement) conn.createStatement();
			String sql;
			sql="select * from miaomiao";
			ResultSet rs=stmt.executeQuery(sql);
			
			while(rs.next()){
				String name=rs.getString("name");
				String pwsd=rs.getString("pwsd");
				System.out.print("name="+name);
				System.out.print(",pwsd="+pwsd);
				System.out.println("\n");
			}
			rs.close();
			stmt.close();
			conn.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
				try {
					if(stmt!=null){
					stmt.close();
					}
					if(conn!=null){
						conn.close();
					}
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
		System.out.println("结束了数据库操作！");
	}
}
